//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.TridentModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;

    public abstract class TridentBaseVisitor
    {
        private Stack<BaseCompositeModel> compositeModelStack = new Stack<BaseCompositeModel>();
        public virtual BaseCompositeModel CurrentCompositeModel
        {
            get
            {
                BaseCompositeModel compModel = null;
                if (this.compositeModelStack.Count > 0)
                {
                    compModel = this.compositeModelStack.Peek();
                }

                return compModel;
            }
        }

        public abstract void VisitCompositeActivityModel(CompositeActivityModel tridentCompositeActivityModel);
        public abstract void VisitSimpleActivityModel(SimpleActivityModel tridentSimpleActivityModel);
        public abstract void VisitSubsectionModel(TridentSubsectionModel tridentSubsectionModel);
        public abstract void VisitForActivityModel(ForActivityCompositeModel tridentForActivityCompositeModel);
        public abstract void VisitReplicatorActivityModel(ReplicatorActivityCompositeModel tridentReplicatorActivityCompositeModel);
        public abstract void VisitIfElseActivityModel(IfElseActivityCompositeModel tridentIfElseActivityCompositeModel);
        public abstract void VisitSimpleBlackboxModel(SimpleBlackboxModel simpleBlackBoxModel);
        public abstract void VisitCompositeBlackboxModel(CompositeBlackboxModel compositeBlackboxModel);

        protected virtual void Walker(BaseModel model)
        {
            model.Accept(this);
            BaseCompositeModel compositeModel = model as BaseCompositeModel;
            if (compositeModel != null)
            {
                this.compositeModelStack.Push(compositeModel);
                for (int iterator = 0; iterator < compositeModel.Children.Count; iterator++)
                {
                    this.Walker(compositeModel.Children[iterator]);
                }

                this.compositeModelStack.Pop();
            }
        }
    }
}
